﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace KUMC.Neurology.SomatoTopo
{
    public class Selection : Layer
    {
       /*
         * Constructor
         * */
        public Selection(Image image)
            : base(image)
        {
        }
        public Selection(Bitmap bitmap)
            : base(bitmap)
        {
        }
        public Selection(Size size)
            : base(size)
        {
            this.pointList = new List<Point>();
        }
        public Selection(int width, int height)
            : base(width, height)
        {
            this.pointList = new List<Point>();
        }

        /*
         * Methods
         * */
        public override void Clear()
        {
            base.Clear();
            this.pointList.Clear();
        }
        public void SetPen(Color color)
        {
            this.pen = new Pen(color);
            this.pen.DashStyle = DashStyle.Dot;
            this.pen.Width = 3;
        }
        public Point[] GetRegion()
        {
            return this.pointList.ToArray();
        }
        public void SelectRegion()
        {
            if (this.pointList.Count > 1)
            {
                try
                {
                    this.CreateG().DrawLines(this.pen, this.pointList.ToArray());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        public void SelectRegion(Point point)
        {
            if (this.pointList.Count > 0)
            {
                try
                {
                    this.CreateG().DrawLine(this.pen, this.pointList.Last(), point);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            this.pointList.Add(point);
        }
        public void SelectRegion(Point[] points)
        {
            if (points.Length > 1)
            {
                try
                {
                    this.CreateG().DrawLines(this.pen, points);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
               
        /*
         * Member variable
         * */
        private List<Point> pointList = null;
        private Pen pen = null;
    }
}
